package org.zeapp.opencloud.framework.synchro;

public class SynchronizationException extends Exception {

	/**
	 * An exception that provide information on a synchronization failure. Each
	 * SynchronizationException provide the following information
	 * <UL>
	 * <LI>a string description of the exception
	 * <LI>a "faultCode" to identify the exception (easier to speak about
	 * exception than using the string message)
	 * </UL>
	 */

	/** the serial UID */
	private static final long serialVersionUID = 1L;

	/** The fault code */
	private String faultCode;

	/**
	 * Create a new SynchronizationException.
	 * 
	 * @param message
	 *            the description
	 * @param faultCode
	 *            the linked fault code.
	 */
	public SynchronizationException(String message, String faultCode) {
		super(message);
		this.faultCode = faultCode;
	}

	/**
	 * Create a new SynchronizationException.
	 * 
	 * @param message
	 *            the description
	 * @param faultCode
	 *            the linked fault code.
	 * @param cause
	 *            the the underlying reason for this SynchronizationException
	 *            (which is saved for later retrieval by the getCause() method);
	 *            may be null indicating the cause is non-existent or unknown.
	 */
	public SynchronizationException(String message, String faultCode,
			Throwable cause) {
		super(message, cause);
		this.faultCode = faultCode;
	}

	/**
	 * Return the fault code for this SynchronizationException object.
	 * 
	 * @return the fault code
	 */
	public String getFaultCode() {
		return faultCode;
	}

	/**
	 * Return the concatenation of the fault code and the message description,
	 * or the only the message description if the fault code is null.
	 */
	@Override
	public String getMessage() {
		if (faultCode == null) {
			return super.getMessage();
		} else {
			return faultCode + " - " + super.getMessage();
		}
	}

	/**
	 * Return the message description without the fault code.
	 * 
	 * @return the message description
	 */
	public String getMessageDescription() {
		return super.getMessage();

	}
}
